<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑企业信息</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">
    <link href="<%=path %>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="<%=path %>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="<%=path %>/hplus/css/animate.min.css" rel="stylesheet">
    <link href="<%=path %>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"><link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/datapicker/datepicker3.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/style.min.css"/>
    <style>
        .col-sm-1{
            padding-right: 0;
        }
		JSON
		body {font-size: 14px;padding: 20px;}
		.radio-primary input[type="radio"] + label::after {background-color: #1ab394;}
		.radio-primary input[type="radio"]:checked + label::after {background-color: #1ab394;}
		.radio-primary input[type="radio"]:checked + label::before {border-color: #1ab394;}
		form>div.row{margin-bottom: 16px;}
		a.btn-rounded{margin-right: 16px;}
		.span_error{min-width:200px;color:red;}
    </style>
</head>
<body class="gray-bg">
	<div style="margin:20px;background:#fff; height:100%;">
	<div class="row">
		<div class="col-sm-2" style="height:100%;">
			<form id='logo' enctype='multipart/form-data'>
			<div>
				<div class="x_pt_h" style="margin: 40px;width: 100px;">
					<div class="x_img_sc" style="width:120px;height:120px;">
						<img id="logo_img" src="<%=path%>/images/marketing/img_p.png"
							width="100%" height="100%">
					</div>		
					<input accept="image/gif,image/jpeg,image/x-png"
						type="file" id="x_inputfile"
						onchange="fileloadon()" name="logo"
						style="filter: alpha(opacity = 50); -moz-opacity: 0.5; -khtml-opacity: 0.5; opacity: 0.0; position: absolute; z-index: 99;cursor: pointer;height: 150px;top: 40px;width: 120px">
						<div class="x_line_h s_fx_li12">
							<center>
							<span style="color:#80D4C1; font-size:13px;font-weight:bold;">上传企业logo</span>
							</center>
							<center>
							<span style="font-size:12px;color:#CACACA;">尺寸120*120像素</span>
							</center>
						</div>
				</div>
			</div>
			</form>
		</div>
		<div class="col-sm-6" style="height:400px;;    margin-top: 20px;">
			<div class="row">
				<div class="form-group">
		     		<label class="col-sm-1 control-label" style="margin-top:10px;min-width:80px;">企业名称</label>
		     		<div class="form-group col-sm-3" style="height: 30px;">
		 			    <input class="form-group form-control" id="company_name" style="min-width:300px;" placeholder="请输入您的企业名称"/>							  	
					</div>
					<div class="form-group" style="margin-left:400px; margin-top:20px;">
						<span id="name_error" class="span_error" ></span>
					</div>			
		     	</div>
			</div>
			<div class="row">
				<div class="form-group" style="margin-top:-10px;">
		     		<label class="col-sm-1 control-label" style="margin-top:10px;min-width:80px;">关键词</label>
		     		<div class="form-group col-sm-3" style="height: 30px;">
		 			    <input class="form-group form-control" id="key_words" style="min-width:300px;" placeholder="多个关键词用逗号隔开"/>							  	
					</div>	
					<div class="form-group" style="margin-left:400px; margin-top:20px;">
						<span id="keywords_error" class="span_error" ></span>
					</div>			
		     	</div>
			</div>
			<div class="row">
				<div class="form-group" style="margin-top:-10px;">
		     		<label class="col-sm-1 control-label" style="margin-top:10px;min-width:80px;">企业电话</label>
		     		<div class="form-group col-sm-3" style="height: 30px;">
		 			    <input class="form-group form-control" id="company_phone" style="min-width:300px;" placeholder="请输入您的企业电话"/>							  	
					</div>		
					<div class="form-group" style="margin-left:400px; margin-top:20px;">
						<span id="phone_error" class="span_error" ></span>
					</div>		
		     	</div>
			</div>
			<div class="row">
				<div class="form-group" style="margin-top:-10px;">
		     		<label class="col-sm-1 control-label" style="margin-top:10px;min-width:80px;">企业地址</label>
		     		<div class="form-group col-sm-3" style="height: 20px;">
		 			    <input class="form-group form-control" id="company_address" style="min-width:300px;" placeholder="请输入您的企业地址"/>							  	
					</div>	
					<div class="form-group" style="margin-left:400px; margin-top:20px;">
						<span id="address_error" class="span_error"></span>
					</div>			
		     	</div>
			</div>
			<div class="row">
				<div class="form-group" style="margin-top:-10px;height:100px;">
		     		<label class="col-sm-1 control-label" style="margin-top:40px;min-width:80px;">企业简介</label>
		     		<div class="form-group col-sm-3" style="height:100px;">
		     			<textarea class="form-group form-control " id="company_introduction" style="min-width: 300px;height:100px; margin-top:20px"placeholder="请输入您的企业简介"></textarea>
					</div>	
					<div  style="margin-left:400px;padding-top:50px;">
						<span id="introduction_error" class="span_error"></span>
					</div>			
		     	</div>
			</div>
			
			<div class="row">
			     <div class="col-sm-1"></div>
				 <div class="form-group">
	                  <div class="col-sm-8 col-sm-offset-1" style="margin-top:30px; ">             
					    <%-- 
					    	<button type="button" class=" btn btn-outline btn-primary col-sm-5" id="close" style="margin-right:20px;width:100px;"onclick="window.location.href='${pageContext.request.contextPath}/view/ui/mainView?menuId=150&amp;menuName=设置'">返回</button>   
	                  	--%>  &nbsp;&nbsp;&nbsp;&nbsp;    
	                  	<shiro:hasPermission name="company_info:save">    
						<button id="save" type="button" class=" btn btn-primary k_verify col-sm-5" style="width:100px" >保存</button>
						</shiro:hasPermission>
				     </div>
			     </div>
	    	</div>
	    	
		</div>
		
		
		
		
	    
	    
	</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/artDialog/7.0.0/dialog-plus.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="<%=basePath%>hplus/js/plugins/jsKnob/jquery.knob.js"></script>
<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
<script type="text/javascript" src="<%=path%>/js/marketing/jquery-form.js"></script>
<script type="text/javascript">
	var access_token=$.cookie('access_token');
	var cid=$.cookie('cid');
	var uid=$.cookie('uid');
	var path = "<%=path%>";
	var name="";
	var address="";
	var keyWords="";
	var phone="";
	var introduction="";
	var logo="";
	var flag=true;
	function getDatas(){
		flag=true;
		if(flag&&StringEmpty($("#company_name").val())){
			name=$("#company_name").val();
			if(16>name.length){
				$("#name_error").html("");
			}else{
				flag=false;
				$("#name_error").html("企业名称不超过15个字符！");
			}			
		}else{
			flag = false;
			$("#name_error").html("企业名称不能为空！");
		}
		if(flag){
			if(flag&&StringEmpty($("#key_words").val())){
				keyWords=$("#key_words").val();
				if(16>keyWords.length){
					$("#keywords_error").html("");
				}else{
					flag=false;
					$("#keywords_error").html("关键字不超过15个字符！");
				}
			}else{
				flag=false;
				$("#keywords_error").html("关键字不能为空！");
			}
		}
		var reg = /^((0|[2-9])[0-9]{2,3})?(\-)?([2-9][0-9]{3,7})+(\-)?([0-9]{0,8})?$/;
		if(flag){
			if(flag&&StringEmpty($("#company_phone").val())){
				phone=$("#company_phone").val();
				if(reg.test($("#company_phone").val())||/^1[34578]\d{9}$/.test($("#company_phone").val())){
					$("#phone_error").html("");
				}else{
					flag = false;
					$("#phone_error").html("企业电话格式不正确！");
				}
			}else{
				flag=false;
				$("#phone_error").html("企业电话不能为空！");
			}
		}
		if(flag){
			if(flag&&StringEmpty($("#company_address").val())){
				address=$("#company_address").val();
				if(31>address.length){
					$("#address_error").html("");
				}else{
					flag=false;
					$("#address_error").html("企业地址不超过30个字符!");
				}
			}else{
				flag=false;
				$("#address_error").html("企业地址不能为空！");
			}
		}
		if(flag){
			if(flag&&StringEmpty($("#company_introduction").val())){
				introduction=$("#company_introduction").val();
				if(51>introduction.length){
					$("#introduction_error").html("");
				}else{
					flag=false;
					$("#introduction_error").html("企业简介不超过50个字符!");
				}
			}else{
				flag=false;
				$("#introduction_error").html("企业简介不能为空！");
			}
		}
		if(StringEmpty(logo)){   		                    
		}else{
			flag=false;
			func_artdialog("提示", "请上传logo");
		}
	}
	$("#company_name").blur(function(){
		if(StringEmpty($("#company_name").val())){
			name=$("#company_name").val();
			if(16>name.length){
				$("#name_error").html("");
			}else{
				flag=false;
				$("#name_error").html("企业名称不超过15个字符！");
			}			
		}else{
			flag=false;
			$("#name_error").html("企业名称不能为空！");
		}
	});
	$("#company_phone").blur(function(){
		var reg = /^((0|[2-9])[0-9]{2,3})?(\-)?([2-9][0-9]{3,7})+(\-)?([0-9]{0,8})?$/;
		if(StringEmpty($("#company_phone").val())){
			phone=$("#company_phone").val();
			if(reg.test($("#company_phone").val())||/^1[34578]\d{9}$/.test($("#company_phone").val())){
				$("#phone_error").html("");
			}else{
				flag=false;
				$("#phone_error").html("企业电话格式不正确！");
			}
		}else{
			flag=false;
			$("#phone_error").html("企业电话不能为空！");
		}
	});
	$("#key_words").blur(function(){
		if(StringEmpty($("#key_words").val())){
			keyWords=$("#key_words").val();
			if(16>keyWords.length){				
				$("#keywords_error").html("");
			}else{
				flag=false;
				$("#keywords_error").html("关键字不超过15个字符!");
			}
		}else{
			flag=false;
			$("#keywords_error").html("关键字不能为空!");
		}
	});
	$("#company_address").blur(function(){
		if(StringEmpty($("#company_address").val())){
			address=$("#company_address").val();
			if(31>address.length){
				$("#address_error").html("");
			}else{
				flag=false;
				$("#address_error").html("企业地址不超过30个字符!");
			}
		}else{
			flag=false;
			$("#address_error").html("企业地址不能为空！");
		}
	});
	$("#company_introduction").blur(function(){
		if(StringEmpty($("#company_introduction").val())){
			introduction=$("#company_introduction").val();
			if(51>introduction.length){
				$("#introduction_error").html("");
			}else{
				flag=false;
				$("#introduction_error").html("企业简介不超过50个字符!");
			}
		}else{
			flag=false;
			$("#introduction_error").html("企业简介不能为空！");
		}
	});
	
	
	$("#save").click(function (){
		getDatas();
		var url = "<%=path%>/company/ajaxUpdateCompanyInfo";
		if(flag){
			$.post(url,{
				/* "cid" : cid,
            	"uid" : uid,
            	"access_token" : access_token, */
            	"name":name,
				"officePhone":phone,
				"address":address,
				"intro":introduction,
				"business":keyWords,
				"logo":logo
			},function(data){
					if("修改企业信息失败"==data.message){						
						func_artdialog("提示","修改失败,请重新修改!");
					}else{
						func_artdialog("提示","修改成功!");
					}
				});
		}
	});
	
	//初始化企业信息
	$(function(){
		$.post(
			"<%=path%>/company/ajaxCompanyInfo" , 
			function(e){
				$("#company_name").val(e.data.name);
				$("#key_words").val(e.data.business);
				$("#company_phone").val(e.data.officePhone);
				$("#company_address").val(e.data.address);
				$("#company_introduction").html(e.data.intro);
				if(StringEmpty(e.data.logo)){
					$("#logo_img").attr("src" , e.data.logo);
					logo = e.data.logo;
				}			
		});
	});
	
	 function fileloadon() {
	        var isSuccess = false;
	        $("#logo").submit(function () {
	            if (isSuccess) {
	                return;
	            }
	            flag = true;
	            $("#logo").ajaxSubmit({
	                type: "post",
	                url: "${pageContext.request.contextPath}/api/uploadfile/file",
	                data: {"typename": "logo"},
	                success: function (e) {
		                    logo = e.realSavePath+"?x-oss-process=image/resize,m_fixed,h_120,w_120";
		                    $("#logo_img").attr("src",logo);
	                	/* if(data1.error_code=="0"){
	                		//压缩大小为120*120
	                	}else{
	                		func_artdialog("提示",data1.error_msg);
	                	}   */            
	                },
	                error: function (msg) {
	                    func_artdialog("提示", msg);
	                }
	            });
	            return false;
	        });
	        $("#logo").submit();
	    }
	  	//自定义弹框
	  	function func_artdialog(name,value){
	 		var d = dialog({
	 			title: name,
	 			fixed: true,
	 			width: 200,
	 	        height:100,
	 			content:"<center style='font-size:20px; line-height:100px;'>"+value+"</center>",
	 			okValue: "确定",
	 			ok: function () {
	 				return true;
	 			}
	 		});
	 		d.show();
	 	}
	 //判断字符串是否为空
	function StringEmpty(content) {
		if (content == undefined || content == "" || content == null) {
			return false;
		} else {
			return true;
		}
	}
</script>
</body>
